package client;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;

import server.Global;

public class Client 
{
        private  String name=null;
        private  int sex;
        private  int grade=0;
        private  String position=null;
        private  String groupName=null;        
        private  HashMap<String,Per_Info>  friendList = new HashMap<String,Per_Info>();//to save all the friends
        private  HashMap<String,Per_Info>  GroupMemList = new HashMap<String,Per_Info>();//to save all the GroupMember
        private  ArrayList<String>  posList = new ArrayList<String>();
        private  ArrayList<String> GnameList = new ArrayList<String>();
        public  Socket s=null;//to send request,and get 1,2
        public  Socket s2=null;//to receive request,and maybe send YES,NO
        public  BufferedReader  in;
        public  PrintWriter out;
        public  BufferedReader  in2;
        public  PrintWriter out2;
        public  BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
        public ClientReadThread clientReadThread = new ClientReadThread(this);
    	public ClientSendThread clientSendThread = new ClientSendThread(this);
        static final int PORT = 33333;
        //to connnect to Server
        public void  connectToServer(int temp) 
        {
         
          try {
        	    System.out.println("新端口号="+(PORT+temp));
        		ServerSocket serverSocket=new ServerSocket(PORT+temp,1);
			    s = new Socket("127.0.0.1",PORT);//create socket and connect to the sever
			    s2=serverSocket.accept();
		      } 
          catch (UnknownHostException e1) {   e1.printStackTrace();	} 
		  catch (IOException e2)          {   e2.printStackTrace();}
		        
           try {
        	   //to define the input and output Stream of the socket
        	   in = new BufferedReader(new InputStreamReader(s.getInputStream()));
   			   out = new PrintWriter(s.getOutputStream());
   			   in2 = new BufferedReader(new InputStreamReader(s2.getInputStream()));
  			   out2 = new PrintWriter(s2.getOutputStream());
		       } catch (IOException e) { e.printStackTrace();		}
		   	  clientReadThread.start();
        	  clientSendThread.start();
        	 
        	  //to init the posList of client
        	  BufferedReader in;
			 try {
				 in = new BufferedReader(new FileReader("location.txt"));
				 String ins  = null;
	  			 while (null != (ins = in.readLine()))
	  			 {
	  				 String af[] =ins.split("\\s+");
	  				 posList.add(af[0]);
	  				 
	  			 }
	  			 
	  			 //to check the posList
	  			 System.out.println(" after connectToServer check the posList");
	  			 for(int i=0;i<posList.size();i++)
	  				 System.out.println(posList.get(i));
			    } 
			     catch (FileNotFoundException e) {	e.printStackTrace();	}
			     catch (IOException e) {	e.printStackTrace();	}
			     
              System.out.println("------connect to the sever succeed-----");
               
        }
        //to send the request logOn to the sever????
        private int logOn(String name,String passwd)
        {
        	String req ="logon"+"\t"+name+"\t"+passwd;
            String ans=clientSendThread.sendMessage(req);
			//处理个人信息 
    		//用户个人信息设置
    		//好友的相关信息
    		//地理位置以及群组的相关信息
			if((ans!=null) && (ans.startsWith("1")))
			{
				String []af = ans.split("\\s+");
				this.name=name;
				System.out.println("更新用户个人信息");
				this.sex = new Integer(af[1]).intValue();
				this.grade = new Integer(af[2]).intValue();
				this.groupName=null;
				this.position=null;
				String friendName = af[3];//FriendListByName name split with ;
				System.out.println(friendName);
				String friendSex = af[4];//FriendSexByName
				String friendLogin =af[5];//FriendLoginByName
				String friendPos =af[6];//FriendPosByName
				String friendGrade =af[7];//FriendGradeByName
				String friendGname =af[8];//FriendGnameByName
				String Gname =af[9];//GnameByLocation groupname only,split with ;
				String []gf =  Gname.split(";");
				if(friendName!=null && !friendName.isEmpty())
				{
					System.out.println("好友信息不为空");
					String []bf =  friendName.split(";");
					String []cf =  friendSex.split(";");
					String []df =  friendLogin.split(";");
					String []ef =  friendPos.split(";");
					String []ff =  friendGrade.split(";");
					String []hf =  friendGname.split(";");
					for(int i=0;i<bf.length;i++)
						friendList.put(bf[i], new Per_Info(
								bf[i],new Integer(cf[i]).intValue(),new Integer(df[i]).intValue(),ef[i],new Integer(ff[i]).intValue(),hf[i]));
					System.out.println("好友信息="+this.friendList.toString());
					System.out.println("好友信息="+this.friendList.keySet().toString());
				}
				for(int i=0;i<gf.length;i++)
				{
					GnameList.add(gf[i]);			
				}
	        	return 1;
		    }
			else if((ans!=null) && (ans.startsWith("8")))
			{
				return 8;
			}
		    else //2
	           return 2;
        }
        
        //to send the name to the server for  register
        //if the name is used,return 3;
        public int checkName(String name)
        {
        	  String req ="nuser"+"\t"+name;
        	  String ans=clientSendThread.sendMessage(req);
  			  if((ans!=null) && (ans.startsWith("1")))
  				 return 1;
			  else //3
	        	 return 3;
        }
 
        //to send the sex and password to the server for  register
        //if error,return 2;
        public int register(String name,int sex,String passwd)
        {
        	if(this.checkName(name)==1)
        	{
        	    this.name=name;
        	    String req ="npasswd\t"+name+"\t"+passwd+"\t"+sex;
        	    String ans=clientSendThread.sendMessage(req);
        	    String []af = ans.split("\\s+");
        	    this.sex = new Integer(af[1]).intValue();
			    this.grade = new Integer(af[2]).intValue();
				String Gname =af[3];//GnameByLocation groupname only,split with ;
				String []ff =  Gname.split(";");
				for(int i=0;i<ff.length;i++)
				{
					GnameList.add(ff[i]);
				}
  			   if((ans!=null) && (ans.startsWith("1")))
  			 	  return 1;
		       else //2
	             return 2;
        	}
        	else
        		 return 3;
        } 
        
        //to send position information to the server for  checkIN
        //if the position is invalid,return 7;
        //automaticcally addIn the  group
        //if the group is null,create the group
        public int checkIN(String pos)
        {
        	pos=pos.trim();
        	String checkPosGname =null;
        	for(int i=0; i<posList.size(); i++)
        	{
        		    System.out.println("0 "+posList.get(i)+"\t"+GnameList.get(i));
        		    String temp = posList.get(i).trim();
        		    if(temp.endsWith(pos))
					{
						checkPosGname=GnameList.get(i);
						System.out.println("1 "+posList.get(i)+"\t"+GnameList.get(i));
					}
        	}
        	
        	System.out.println(checkPosGname);
        	
        	if(checkPosGname.equals("0"))
        	{
        		System.out.println("客户端自己创建群组");
        		checkPosGname = creatNewGroup(pos);//the groupName can't be null
        		System.out.println(checkPosGname);
        		this.position=pos;
        		this.groupName=checkPosGname;
        		String req ="checkIN\t"+pos+"\t"+this.name+"\t"+this.groupName;
                String ans=clientSendThread.sendMessage(req);
          		if((ans!=null) && (ans.startsWith("1")))
          		{
          			//to add new group name          	
                     	for(int i=0;i<posList.size();i++)
                     	{
          					if(posList.get(i).endsWith(pos))
          					{
          						GnameList.set(i, this.groupName);
          						System.out.println("2 "+posList.get(i)+"\t"+GnameList.get(i));
          					}
                     	}
          			//add myself to the new group
          		    //Per_Info(String name,int sex, int islogin,String position)
          			GroupMemList.put(this.name,new Per_Info(this.name,this.sex,1,pos,this.grade,this.groupName));
          			System.out.println("更新后");
                	System.out.println("posList\tGnameList");
                	for(int i=0;i<this.posList.size();i++)
                		System.out.println(posList.get(i)+"\t"+GnameList.get(i));
                	System.out.println(this.GroupMemList.keySet().toString());
                	System.out.println(this.GroupMemList.toString());
          			return 1;
        	    }
          		return 2;
        	}
          	else
          	{
          		System.out.println("客户端自己加入群组");         		
          		this.position=pos;
        		this.groupName=checkPosGname;
          		String req ="checkIN\t"+this.position+"\t"+this.name+"\t"+this.groupName;
                String ans=clientSendThread.sendMessage(req);
                String af[] = ans.split("\\s+");
                String nameList=af[1];
				String sexList=af[2];
				String gradeList=af[3];
				String gnameList=af[4];
				String names[]=nameList.split(";");
				String sexs[]=sexList.split(";");
				String grades[]=gradeList.split(";");
				String gnames[]=gnameList.split(";");
				for(int i=0;i<names.length;i++)
					this.GroupMemList.put(names[i],new Per_Info(names[i],new Integer(sexs[i]).intValue(),1,pos,new Integer(grades[i]).intValue(),gnames[i]));
				GroupMemList.put(this.name,new Per_Info(this.name,this.sex,1,pos,this.grade,this.groupName));
				return 1;  
          	}         			     			
        } 
         
        //checkOFF [place] [NameFrom] [gname]
        public int checkOFF()
        {
        	if(this.groupName == null)
        	{}
          	else
          	{
          		String req ="checkOFF\t"+this.position+"\t"+this.name+"\t"+this.groupName;
                String ans=clientSendThread.sendMessage(req);
                if(ans.startsWith("1"))
                {
                	this.position=null;
                	this.groupName="0";
                	this.GroupMemList.clear();
                }			  
          	} 
        	return 1;
        } 
        
        //to send position information to the server for  checkIN
        public int  helpCheckIN(String nameto,String pos)
        {
        	pos=pos.trim();
        	if(null==this.position || !this.position.equals(pos))
        	{
        		//输出提示信息当用户不在本地时无法帮助该好友checkIN
        		System.out.println("before you helpCheckIN,you need to CheckIN");
        		return 2;
        	}
        	else
        	{
        		String req ="helpCheckIN\t"+nameto+"\t"+this.position+"\t"+this.name;
        		String ans=clientSendThread.sendMessage(req);
        		System.out.println("ans:"+ans);
        		if((ans!=null) && (ans.startsWith("1")))
        			return 1;
        		else if(ans.equals("5"))//the limit wrong that means the user set canHelp=0 or he don't agree
        			return 5;	
        		else if(ans.equals("6"))//user para islogin=0，that means he has not logIn
        			return 6;
        		else //the pos is invalid
        			return 7;
        	}
        } 
        
        //to  addFred
        public int addFred(String fredName)
        {
        	String req ="AddFred\t"+fredName+"\t"+this.name+"\t"+this.sex+"\t1\t"+this.position+"\t"+this.grade+" "+this.groupName;
        	String ans=clientSendThread.sendMessage(req);
  			if((ans!=null) && (ans.startsWith("1")))
  			{//TODO 将好友信息加入本地好友列表
  				String af[] = ans.split("\\s+");
  			    int sex = new  Integer(af[1]).intValue();
  			    int islogin = new Integer(af[2]).intValue();
  			    String pos = af[3];
  			    int grade =new Integer(af[4]).intValue();
  			    String gname =af[5];
        		friendList.put(fredName, new Per_Info(fredName,sex,islogin,pos,grade,gname));
        		return 1;
        	}
        	else if(ans.equals("5"))//the limit wrong that means the user set canHelp=0 or he don't agree
        		return 5;	
        	else if(ans.equals("6"))//user para islogin=0，that means he has not logIn
        		return 6;
        	else //the user is my friend already
        		return 8;
        } 
        
        //to  chat with other
        public int Chat(String nameTo,String content)
        {
        	String req ="chat\t"+nameTo+"\t"+this.name+"\t"+content;
        	String ans=clientSendThread.sendMessage(req);
  			if((ans!=null) && (ans.startsWith("1")))
  				return 1;
        	else  //the limit wrong that means the user set canIntr=0;
        		return 5;	
    
        } 
        
        //to   interact  with other,actId
        // 0 : say hello
        // 1 : Clap and so on
        public int interact(String nameTo,int actId)
        {
        	String req ="Act\t"+nameTo+"\t"+this.name+"\t"+actId;
        	String ans=clientSendThread.sendMessage(req);
  			System.out.println("ans:"+ans);
  			if((ans!=null) && (ans.startsWith("1")))
  				return 1;
        	else  //the limit wrong that means the user set canIntr=0;
        		return 5;	
        } 
        
        //to   group Chat  with others
        public int Gchat(String content)
        {
        	String req ="Gchat\t"+this.groupName+"\t"+this.name+"\t"+content;
        	String ans=clientSendThread.sendMessage(req);
  			if((ans!=null) && (ans.startsWith("1")))
  				return 1;
        	else  //the limit wrong that means the user not in the group(groupName);
        		return 5;	
        } 
        
        //to show FriendList
        public void showFriendList()
        {
        	//客户端转入好友界面，进行好友信息展示
        } 
        //to show the my group
        public void showMyGroup()
        {
        	//客户端转入个人群组界面，展示群组讨论区
        } 
        //to show the user list,reserver
        public void showUserList()
        {
        	//客户端转入用户排行界面
        } 
        
        //set canSeen 
        //0 for all
        //1 for friend only
        //2 for people in the same group
        //3 for no
        //4 need query
        //5 for friend and people in the same group
        public int setcanSeen(int canSeen)
        {
        	String req ="SetSeen\t"+this.name+"\t"+canSeen;
        	String ans=clientSendThread.sendMessage(req);
  			if((ans!=null) && (ans.startsWith("1")))
  				return 1;//return the FriendList
        	else  
        		return 2;	
        }
        
        //set canIntr
        //0 for all
        //1 for friend only
        //2 for people in the same group
        //3 for no
        //4 need query
        //5 for friend and people in the same group
        public int setcanDisturb(int canIntr)
        {
        	String req ="SetDisturb\t"+this.name+"\t"+canIntr;
        	String ans=clientSendThread.sendMessage(req);
  			System.out.println("ans:"+ans);
  			if((ans!=null) && (ans.startsWith("1")))
  				return 1;//return the FriendList
        	else  
        		return 2;	
        } 
        
        //set canHelp
        //0 for all
        //1 for friend only
        //2 for people in the same group
        //3 for no
        //4 need query
        //5 for friend and people in the same group
        public int setcanHelp(int canHelp)
        {
        	String req ="SetHelp\t"+this.name+"\t"+canHelp;
        	String ans=clientSendThread.sendMessage(req);
  			if((ans!=null) && (ans.startsWith("1")))
  				return 1;//return the FriendList
        	else  
        		return 2;	
        }
        
        //the user logoff
        //the client need to close the socket connect the server
        public int  logOff()
        {
        	String req ="logoff "+this.name;
        	String ans=clientSendThread.sendMessage(req);
        	if((ans!=null) && (ans.startsWith("1")))
        	{
  				return 1;
        	}
        	else  
        		return 2;
        }
        public void doNewGroup(String request)
        {   
        	System.out.println("传来创建新群组的命令");
        	String af[]=request.split("\\s+");
    		if(af.length==3 && !af[1].equals(this.groupName))
    		{
   			
    			System.out.println("不是自己创建的群组");
    			System.out.println("before");
            	System.out.println("posList\tGnameList");
            	for(int i=0;i<this.posList.size();i++)
            		System.out.println(posList.get(i)+"\t"+GnameList.get(i));
    			
            	String gname = af[1];
    			String place = af[2];
    		    if(!place.equals(this.position))
    		    {    
    		    	for(int i=0;i<posList.size();i++)
    		    		if(posList.get(i).endsWith(place))
    		    			GnameList.set(i, gname);
    		    }
    		    
    		    System.out.println("after");
            	System.out.println("posList\tGnameList");
            	for(int i=0;i<this.posList.size();i++)
            		System.out.println(posList.get(i)+"\t"+GnameList.get(i));
    		 }
        }
        public void doDelGroup(String request)
        {
        	System.out.println("before");
        	System.out.println("posList\tGnameList");
        	for(int i=0;i<this.posList.size();i++)
        		System.out.println(posList.get(i)+"\t"+GnameList.get(i));
        	
        	String af[]=request.split("\\s+");
    		if(af.length==3)
    		{
    			String place =af[2];
    		    for(int i=0;i<this.posList.size();i++)
    		    	if(posList.get(i).endsWith(place))
    		    		GnameList.set(i, "0");
    		 }
    		System.out.println("after");
        	System.out.println("posList\tGnameList");
        	for(int i=0;i<this.posList.size();i++)
        		System.out.println(posList.get(i)+"\t"+GnameList.get(i));
        	
        }
        public void doBeHelp(String request)
        {
        	//beHelpCheckIN [place] NameFrom Nameto	
        	System.out.println("before"+this.position);
    		String af[]=request.split("\\s+");
    		if(af.length==4)
    		{
    			String place = af[1];
    			String nameFrom =af[2];
    			//to display the request and to ask the user answer
    			String ask=nameFrom +"want to checkIn"+place+"for you\n,what do you think?";
    			int ans=askUserAns(ask,1);
    			if(ans ==1)  
    			{
    				out2.println("YES");
    			    out2.flush();
    			    this.position=af[1];
    			}
    			else 
    			{
    				out2.println("NO");   
    				out2.flush();
    		    }
    		
    		}
    		System.out.println("after"+this.position);
        }
        
        //beFriend
        public void dobeFred(String request)
        {
        	System.out.println("before");
        	for(String s:this.friendList.keySet())
        		System.out.println(s+"\t"+this.friendList.get(s).toString());
        	//beFred [place] NameFrom Nameto	
    		String af[]=request.split("\\s+");
    		if(af.length>2)
    		{
    			String userfrom =af[1];
    			String userfromsex = af[2];
    			String userfromislogin =af[3];
    			String userfromposition=af[4];
    			String userfromgrade=af[5];
    			String userfromgname=af[6];
    			//to display the request and to ask the user answer
    			String ask=userfrom +"want to add You as a Friend,what do you think?";
    			int ans=askUserAns(ask,1);
    			if(ans ==1)  
    			{
    				out2.println("YES");
    			    out2.flush();
    			    friendList.put(userfrom,new Per_Info(userfrom,new Integer(userfromsex).intValue(),new Integer(userfromislogin).intValue(),userfromposition,new Integer(userfromgrade).intValue(),userfromgname));
    			}
    			else 
    			{
    				out2.println("NO");   
    				out2.flush();
    			}
    		
    		 }
    		System.out.println("after");
        	for(String s:this.friendList.keySet())
        		System.out.println(s+"\t"+this.friendList.get(s).toString());
        }
        
        //有人传来对话的消息,显示消息对话框以及对话内容
        public void doChat(String request)
        {
        	//chat [Nameto] [NameFrom] [content]
        	String af[]=request.split("\\s+");
    		if(af.length==4)
    		{
    			String nameto = af[1];
    			String nameFrom =af[2];
    			String content=af[3];
    			//to display the content
    			System.out.println("chat: from "+nameFrom+" to "+nameto+" contents:"+content);
    		}	
        }
        //有人传来互动消息，显示互动的提示框
        public void doAct(String request)
        {
        	String af[]=request.split("\\s+");
    		if(af.length==4)
    		{
    			String nameto = af[1];
    			String nameFrom =af[2];
    			int actnum=new Integer(af[3]).intValue();
    			//to display the content
    			System.out.println("Act: from "+nameFrom+" to "+nameto+" actnum:"+actnum);
    		}	
        }
        //有人发起群聊，接收群聊内容即可
        public void doGchat(String request)
        {
        	String af[]=request.split("\\s+");
    		if(af.length==4)
    		{
    			String nameFrom =af[2];
    			String  content=af[3];
    			//to display the content
    			System.out.println("Gchat: from "+nameFrom+"  content:"+content);
    		}	
        }
        //有好友上线
        public void doFredLogOn(String request)
        {
        	String af[] = request.split("\\s+");
        	System.out.println("before "+this.friendList.get(af[1]).get_login());
        	(this.friendList.get(af[1])).set_islogin();
        	System.out.println("after "+this.friendList.get(af[1]).get_login());
        	return;
        }
        //好友下线
        public void doFredLogOff(String request)
        {
        	 String af[] = request.split("\\s+");
             System.out.println("before "+this.friendList.get(af[1]).get_login());
        	 (this.friendList.get(af[1])).set_islogoff();
        	 (this.friendList.get(af[1])).set_position(null);
        	 (this.friendList.get(af[1])).set_gname("0");
        	 System.out.println("after "+this.friendList.get(af[1]).get_login());
        	 return;
        }
        //好友签到
        public void doFredCheckIN(String request)
        {
        	 String af[] = request.split("\\s+");
        	 System.out.println("before "+this.friendList.get(af[1]).get_position());  
        	 System.out.println("before "+this.friendList.get(af[1]).get_gname());      
         	(this.friendList.get(af[1])).set_position(af[2]);	
         	(this.friendList.get(af[1])).set_gname(af[3]);
         	 System.out.println("after "+this.friendList.get(af[1]).get_position());
         	 System.out.println("after "+this.friendList.get(af[1]).get_gname());
        }
        //好友取消签到
        public void doFredCheckOFF(String request)
        {
        	 String af[] = request.split("\\s+");
        	 System.out.println("before "+this.friendList.get(af[1]).get_position());
         	(this.friendList.get(af[1])).set_position(null);
         	(this.friendList.get(af[1])).set_gname("0");
         	 System.out.println("after "+this.friendList.get(af[1]).get_position());
        }
        //减少群组成员
        public void doGroupMemLogOff(String request)
        {
        	 String af[] = request.split("\\s+");
           	 this.GroupMemList.remove(af[1]);	
        }
        //增加群组成员
        public void doGroupMemLogOn(String request)
        {//GroupMemLogOn [Name] [sex] [islogin] [position] [grade]
        	 String af[] = request.split("\\s+");
        	 String mname=af[1];
        	 int  msex =new Integer(af[2]).intValue();
        	 int  mislogin =1;
        	 String mpos=af[4];
        	 int mgrade =new Integer(af[5]).intValue();       	 
           	 this.GroupMemList.put(mname,new Per_Info(mname,msex,mislogin,mpos,mgrade,this.groupName));	
        }
        public int send() 
        {
        	  while(true)
              {    
              	System.out.println("*******Enter your command!************");
              	String cmd=null;
				try {
					cmd = input.readLine();
				} catch (IOException e){e.printStackTrace();}
				
              	String bf[]=cmd.split("\\s+");
              	System.out.println("输入命令的长度="+bf.length);
              	String talk_content="";
              	String Gtalk_content="";
              	for( int i =2;i<bf.length;i++)
              	{
              		talk_content+=bf[i];
              	}
              	for( int i =1;i<bf.length;i++)
              	{
              		Gtalk_content+=bf[i];
              	}
              	for(int i=0;i<bf.length;i++)
              		System.out.print(bf[i]+"\t");
              	System.out.println();
                if(cmd.startsWith("logon"))
                {
                	int ret = logOn(bf[1], bf[2]);
                	System.out.println("ret="+ret);
              	    if(ret != 1)
              	      return ret;
                }
            	else if(cmd.startsWith("logoff"))
            	{
            		logOff();
            		break;
            	}
            	else if(cmd.startsWith("conToServer"))
              	    connectToServer(new Integer(bf[1]).intValue());
              	else if(cmd.startsWith("register"))
              	    register(bf[1],new Integer(bf[2]).intValue(), bf[3]);
              	else if(cmd.startsWith("checkIN"))
              	    checkIN(bf[1]);
            	else if(cmd.startsWith("checkOFF"))
              	    checkOFF();
              	else if(cmd.startsWith("helpCheckIN"))
              	    helpCheckIN(bf[1], bf[2]);
              	else if(cmd.startsWith("addFred"))
              	    addFred(bf[1]);
              	else if(cmd.startsWith("chat"))
              	    Chat(bf[1], talk_content);
              	else if(cmd.startsWith("interact"))
              	    interact(bf[1],new Integer(bf[2]).intValue());
              	else if(cmd.startsWith("Gchat"))
              	    Gchat(Gtalk_content);
              	else if(cmd.startsWith("setcanSeen"))
              	    setcanSeen(new Integer(bf[1]).intValue());
              	else if(cmd.startsWith("setcanHelp"))
              		 setcanHelp(new Integer(bf[1]).intValue());
              	else if(cmd.startsWith("setcanDisturb"))
              		 setcanDisturb(new Integer(bf[1]).intValue());
              	else
              	{}
              }//while
			return 1;
}//end of function
        
        //to display the request and to ask the user answer
		int askUserAns(String dialog,int id)
		{
			
			    String ans = "YES";
				if(ans.equalsIgnoreCase("YES")) return 1;
				else return 0;
		}
		//to ask the user for the new GroupName 
		String creatNewGroup(String pos)
		{
			    String ans="";
				System.out.println("请输入群组名称:");
				ans += "lecture";
				return ans;
		}
		public static void main(String args[]) throws IOException
        {
        	Client a = new Client();
        	if(a.send()==Global.ALREADYLOGON)
        	{
        		System.out.println("该用户已经在其他地方登陆");
        	}
        	System.out.println("退出用户进程");
    		System.exit(0);
         }
}


